<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../../includes/common.jsp" %>
    <title><spring:message code="dictDefine"/></title>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline" action="">
        课件名称
        <input type="text" class="input-medium"
               name="courseName" id="courseName" value=""/>
        课件注册人
        <input type="text" class="input-medium"
               name="userName" id="userName" value=""/>

        <a class="btn btn-primary" onclick="query()"><spring:message code="query"/></a>
    </form>
    <table id="dataTable"></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%"
                id="contentList"
                name="contentList"
                marginheight="0"
                marginwidth="0"
                frameborder="0" src=""
                allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function query() {
        listOption.url = basePath + "courseRegister/listAllCourseRegister";
        listOption.data = "courseName=" + $("#courseName").val().trim() + "&studentName=" + $("#userName").val().trim();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "注册课件列表",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'id', title: "&nbsp<input id='checkAll' type='checkbox' onclick='selectAll()'/>", align: 'center', width: 200},
                    {field: 'upUserName', title: '课件上传人', align: 'center', width: 200},
                    {field: 'courseName', title: '课件名称', align: 'center', width: 200},
                    {field: 'studentName', title: '注册人',  align: 'center', width: 200},
                    {field: 'score', title: '课件评分', sortable: true, align: 'center', width: 200},
                    {field: 'showState', title: '学习状态', align: 'center', width: 200},
                    {field: 'operate', title: '操作', align: 'center', width: 200 }
                ]
            ],
            sortName: "",
            sortOrder: "asc",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "score":
                sortColumn = "score";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        for (var i in temp) {
            var id = "&nbsp;<input type='checkbox' name='deleteCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            var operate = "<a onclick='editCourseRegister(\"" + temp[i].id + "\")'>编辑</a>&nbsp;&nbsp;"
                    + "<a onclick='delCourseRegister(\"" + temp[i].id + "\")'>删除</a>&nbsp;&nbsp;";
            temp[i].id = id;
            temp[i].operate = operate;
        }
        return temp;
    }

    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='deleteCheckBox']").attr("checked", true);
        } else {
            $("[name='deleteCheckBox']").attr("checked", false);
        }
    }

    function editCourseRegister(id) {
        var path = basePath + "courseRegister/editCourseRegisterDo?id=" + id;
        $("#contentList").attr("src", path);
        $('#dataEdit').dialog({
            title: '编辑',
            height: 400,
            width: 600
        }).dialog('open');
    }

    function delCourseRegister(id) {
        $.messager.confirm("提示", "确认删除？", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "courseRegister/delCourseRegister?id=" + id,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("成功", "删除成功！", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
    }

    $(function () {
        initDataGrid();
        query();
    })
</script>
